#include <stdio.h>
#include "treeNode.h"
extern tree_t mTreeRoot;
extern int syntaxError, lexError;
extern int last_error_line;
void yyrestart(FILE *input_file);
int yyparse(void);
extern int yylex();
extern int yyparse();
extern int yydebug;
extern int yylineno;
void localdebug(char *format, ...)
{
#ifdef LOCAL
    va_list args;
    va_start(args, format);
    vprintf(format, args);
    va_end(args);
#endif
}
int main(int argc, char **argv)
{
    mTreeRoot = NULL;
    last_error_line = 0;
    if (argc <= 1)
        return 1;
    FILE *f = fopen(argv[1], "r");
    if (!f)
    {
        perror(argv[1]);
        return 1;
    }
    yyrestart(f);
    yylineno = 1;
    // yydebug = 1;
    yyparse();

    // 判断 要不要打印语法树
    // 有错误，直接返回
    if (syntaxError >0 || lexError >0){
        localdebug("\n\nSyntax Error: %d, Lex Error: %d\n", syntaxError, lexError);
        return 0;
    }
    print_tree(&mTreeRoot);
    // destroy_tree(&mTreeRoot);
    return 0;
}